<template>
<!-- vue3组件中的模板结构可以没有根标签 -->
  <h1 v-show="person.name">姓名：{{person.name}}</h1>
  <h2>年龄：{{person.age}}</h2>
  <h1 v-show="person.sex">性别：{{person.sex}}</h1>
  <h3>工作：{{person.job.type}}</h3>
  <h4>薪水：{{person.job.salary}}</h4>
  <button @click="changeInfo">修改信息</button>
  <button @click="addSex">添加一个sex属性</button>
  <button @click="deleteName">删除一个name属性</button>
</template>

<script>
import { reactive } from '@vue/reactivity'
  export default {
    name: 'App',
    setup(){
      //数据
      let person =reactive({
          name:'张三',
          age:18,
          job:{
            type: 'java工程师',
            salary: '4.5k'
          }
      })
      

      // let number = reactive('678')

      //方法
      function changeInfo() {
        person.name = '李四'
        person.age = 20
        person.job.type = 'java中级工程师'
        person.job.salary = '16k'
      }

      function addSex(){
        person.sex = '男'
      }

      function deleteName(){
        delete person.name
      }

      //返回一个对象
      return {
        person,
        changeInfo,
        addSex,
        deleteName
      }
    }
  }
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
